package com.study.collection.stream.demo;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashSet;
import java.util.function.BinaryOperator;
import java.util.function.Function;
import java.util.function.IntBinaryOperator;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;

public class Test {
    public static void main(String[] args) {
        Stream.of("a-b-c-d", "e-f-i-g-h").flatMap(e -> Stream.of(e.split("-"))).forEach(System.out::println);

        BinaryOperator<Integer> binaryOperator = BinaryOperator.maxBy(Comparator.comparingInt(Integer::intValue));
        Stream.of(2, 4, 5, 6, 7, 1).reduce(binaryOperator).ifPresent(System.out::println);

        IntBinaryOperator intBinaryOperator = Integer::sum;
        IntStream.of(2, 4, 5, 6, 7, 1).reduce(intBinaryOperator).ifPresent(System.out::println);

        //List
        Stream.of(1, 2, 3, 4, 5, 6, 8, 9, 0).collect(Collectors.toCollection(ArrayList::new));
        //Set
        Stream.of(1, 2, 3, 4, 5, 6, 8, 9, 0).collect(Collectors.toCollection(HashSet::new));

        //List
        Stream.of(1, 2, 3, 4, 5, 6, 8, 9, 0).collect(Collectors.toList());
        //Set
        Stream.of(1, 2, 3, 4, 5, 6, 8, 9, 0).collect(Collectors.toSet());

        //Function.identity() 获取这个对象本身
        Stream.of("studentA", "studentB", "studentC").collect(Collectors.toMap(Function.identity(), Function.identity()));
    }
}
